<template>
	<view>
		<template v-if="DengLu_ZhuangTai">
			<template v-if="JSON.stringify(BenYe_PeiZhi) != '{}'">
				<view v-if="GouZi_ZiDingYi_HTML_1">
					<mp-html :content="GouZi_ZiDingYi_HTML_1" :selectable="true"/>
				</view>
				<view class="YouRan-UI-CaiDan-3">
					<view class="XunHuan Flex" @click="$_TiaoZhuan('XiaoXi/XiaoXi_TongYong_LieBiao?types=7&Title=提到了你')">
						<view class="Zuo">
							<image :src="BenYe_PeiZhi.TiJi" mode="widthFix"></image>
						</view>
						<view class="Zhong H2 H2-Line">{{BenYe_PeiZhi.TiJi_Zi}}</view>
						<view class="You Flex">
							<text class="YouCe-TiShi H3 H3-Line Flex Bj-HongSe" v-if="Shu_TiJi">{{Shu_TiJi}}</text>
							<text class="iconfont icon-arrow-double-right Zt-ZhanWeiSe H3 H3-Line"></text>
						</view>
					</view>
					<view class="XunHuan Flex" @click="$_TiaoZhuan('XiaoXi/XiaoXi_TongYong_LieBiao?types=8&Title=回复了你')">
						<view class="Zuo">
							<image :src="BenYe_PeiZhi.PingLun" mode="widthFix"></image>
						</view>
						<view class="Zhong H2 H2-Line">{{BenYe_PeiZhi.PingLun_Zi}}</view>
						<view class="You Flex">
							<text class="YouCe-TiShi H3 H3-Line Flex Bj-HongSe" v-if="Shu_HuiFu">{{Shu_HuiFu}}</text>
							<text class="iconfont icon-arrow-double-right Zt-ZhanWeiSe H3 H3-Line"></text>
						</view>
					</view>
					<view class="YouRan-UI-FenGe-1-BiaoTi-1 Flex">
						<view class="Zuo Flex">
							<view class="Xian" style="background: #409EFF;"></view>
							<view>对话消息</view>
						</view>
					</view>
					
					<template v-if="QingQiu_DuiHua_LieBiao_ZhuangTai=='YouShuJu'">
						<view
							v-for="item in QingQiu_DuiHua_LieBiao"
							@click="$_TiaoZhuan(`XiaoXi/XiaoXi_DuiHua?id=${item.id}&uid=${item.user.uid}`)"
							@longpress="ChangAn_ShanChu_Ben_DuiHua(item.id)"
							class="YouRan-UI-YongHu-1 Flex">
							<view class="Zuo">
								<view class="TouXiang">
									<image :src="item.user.avatar" mode="widthFix"></image>
								</view>
								<view class="YouXia Bj-LanSe" v-if="item.user.roleName=='普通会员'">普</view>
								<view class="YouXia Bj-HongSe" v-if="item.user.roleName=='管理员'">管</view>
							</view>
							<view class="Zhong">
								<view class="Zhong-Shang Flex">
									<view class="NiCheng H2">{{item.user.nickname}}</view>
									<text class="P">{{item.user.roleName}}</text>
									<text class="P">{{item.latestMessage.datetimeFormat}}</text>
								</view>
								<view class="Zhong-Xia Flex">
									<text class="P YiHang">{{item.latestMessage.message}}</text>
								</view>
							</view>
							<view class="You Flex">
								<view class="AnNiu Flex">
									<text class="P" v-if="item.unreadCount != 0">未读 {{item.unreadCount}}</text>
									<text class="P" v-if="item.unreadCount == 0">长按删除</text>
								</view>
							</view>
						</view>
					</template>
					<template v-if="QingQiu_DuiHua_LieBiao_ZhuangTai=='JiaZaiZhong'">
						<YouRan-UI-JiaZaiZhong LeiXing="JuBu"></YouRan-UI-JiaZaiZhong>
					</template>
					<template v-if="QingQiu_DuiHua_LieBiao_ZhuangTai=='WuShuJu'">
						<view class="YouRan-UI-WuShuJu-1 Flex" style="padding: 50rpx 0;height: auto;">
							<text class="iconfont icon-cry Zt-ZhanWeiSe"></text>
							<view class="Zt-ZhanWeiSe">暂无任何对话</view>
						</view>
					</template>
				</view>
			</template>
			<template v-else>
				<YouRan-UI-JiaZaiZhong LeiXing="JuBu"></YouRan-UI-JiaZaiZhong>
			</template>
		</template>
		<template v-else>
			<view class="YouRan-UI-WuShuJu-1 Flex">
				<text class="iconfont icon-cry Zt-ZhanWeiSe"></text>
				<view class="Zt-ZhanWeiSe">暂未登录，请登陆</view>
			</view>
		</template>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				DengLu_ZhuangTai:false,
				BenYe_PeiZhi:{},
				QingQiu_DuiHua_LieBiao:[],
				QingQiu_DuiHua_LieBiao_ZhuangTai:"JiaZaiZhong",
				
				Shu_TiJi:"",
				Shu_HuiFu:"",
				GouZi_ZiDingYi_HTML_1:"",
			}
		},
		onShow() {
			if(uni.getStorageSync("YongHuXinXi")){
				this.QingQiu_PeiZhi();
				this.DengLu_ZhuangTai = true;
				this.$_ShiFou_You_XiaoXi();
			}else{
				this.DengLu_ZhuangTai = false;
			}
		},
		onLoad() {

		},
		methods: {
			// 请求本页配置
			QingQiu_PeiZhi(){
				uni.request({
					url:this.$_PeiZhi_WenJian() + "XiaoXi.json",
					method:"GET",
					success: (res) => {
						this.BenYe_PeiZhi = res.data;
						this.GouZi_ZiDingYi_HTML_1 = res.data.ZiDingYi_HTML_1;
						this.QingQiu_XiaoXi_TiaoShu();
					}
				})
			},
			QingQiu_XiaoXi_TiaoShu(){
				this.$_QingQiu(
					"GET","/api/v2/user/panel", {},
					(res) => {
						this.Shu_TiJi = res.data.data.unreadNotifications.mentions;
						this.Shu_HuiFu = res.data.data.unreadNotifications.comments;
						this.QingQiu_SiLiao_DuiHua();
					}
				)
			},
			// 请求，私聊，对话
			QingQiu_SiLiao_DuiHua(){
				this.$_QingQiu(
					"GET","/api/v2/conversation/list", {},
					(res) => {
						this.QingQiu_DuiHua_LieBiao = res.data.data.list;
						if(this.QingQiu_DuiHua_LieBiao.length){
							this.QingQiu_DuiHua_LieBiao_ZhuangTai = "YouShuJu"
						}else{
							this.QingQiu_DuiHua_LieBiao_ZhuangTai = "WuShuJu"
						}
					}
				)
			},
			// 长按，删除，本，对话
			ChangAn_ShanChu_Ben_DuiHua(e){
				let id = e;
				uni.showModal({
					title: "提示",
					content: "是否删除本会话？数据不可恢复哟",
					success: (res) => {
						if(res.confirm) {
							uni.showLoading({ title: "删除中" });
							this.$_QingQiu(
								"DELETE","/api/v2/conversation/delete",
								{
									"type":"conversation",
									"conversationId":id
								},
								(res_) => {
									uni.hideLoading();
									if(res_.data.code == 0){
										this.QingQiu_DuiHua_LieBiao = [];
										this.QingQiu_PeiZhi();
										this.$_ShiFou_You_XiaoXi();
									}else{
										uni.showToast({
											title:res_.data.message,
											icon:"none",
											duration:1000
										});
									}
								}
							)
						}
					}
				});
			},
		},
		// 下拉，加载
		onPullDownRefresh() {
			if(uni.getStorageSync("YongHuXinXi")){
				this.QingQiu_DuiHua_LieBiao_ZhuangTai = "JiaZaiZhong";
				this.QingQiu_PeiZhi();
				this.DengLu_ZhuangTai = true;
				this.$_ShiFou_You_XiaoXi();
			}else{
				this.DengLu_ZhuangTai = false;
			}
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 500);
		},
	}
</script>

<style lang="scss">
.YouRan-UI-FenGe-1-BiaoTi-1{
	padding: 25rpx;
	border-bottom: 1rpx solid $BeiJingSe;
	border-top: 25rpx solid $BeiJingSe;
}
.YouRan-UI-YongHu-1{
	padding: 25rpx;
	border-bottom: 1rpx solid $BeiJingSe;
	.You{
		.AnNiu{
			height: 32rpx;
			padding: 0 10rpx;
			background: $HongSe;
			border: 1rpx solid $HongSe;
			.P{
				color: #FFF;
			}
		}
	}
}
.YouRan-UI-WuShuJu-1{
	width: 100%;
	height: 90vh;
	align-items: center;
	justify-content: center;
}
</style>